import requests
import json

URL = 'https://enroll.zekdot.com:7007/api/register-consumer/';
GET_DATA_URL = URL + '/enroll/enrollDataByToken';
CHECK_USR_URL = URL + '/enroll/checkUserByToken';

def getData(eId,token,length):
    if(len(eId) != 32 or len(token) != 32):
        raise Exception('报名id或token格式不正确')
    # 获取返回结果
    resText = requests.get(GET_DATA_URL + '?eId=' + eId + '&operaToken=' + token + '&length=' + str(length)).text   
    # 转换成字典 
    res = json.loads(resText)
    # 判断是否出了问题
    if(res['code'] != 0):
        raise Exception(res['message'])
    users = res['object'];
    # 把所有用户的回答都转换成list类型
    for user in users:
        user['content'] = json.loads(user['content']);
    return users;
def submitReq(eId,token,reqArrayStr):
    data = {'eId':eId,'operaToken':token,'reqArrayStr':reqArrayStr};
    resText = requests.post(CHECK_USR_URL,data).text
    res = json.loads(resText)
    # 判断是否出了问题
    if(res['code'] != 0):
        raise Exception(res['message'])
